package com.pcbly.web.action.jbpm;

import java.io.InputStream;

import com.pcbly.web.action.BaseAction;
import com.pcbly.web.business.jbpm.JbpmService;
import com.pcbly.web.components.utils.jbpm.XmlToProcessImage;

@SuppressWarnings("unchecked")
public class JpdlAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5395809180370675003L;

	private JbpmService jbpmService;

	private String piId;
	private InputStream resourceFromProcessInstance;
	private InputStream resourceFromProcessDefinition;

	public InputStream getResourceFromProcessInstance() {
		return resourceFromProcessInstance;
	}

	public void setResourceFromProcessInstance(
			InputStream resourceFromProcessInstance) {
		this.resourceFromProcessInstance = resourceFromProcessInstance;
	}

	public InputStream getResourceFromProcessDefinition() {
		return resourceFromProcessDefinition;
	}

	public void setResourceFromProcessDefinition(
			InputStream resourceFromProcessDefinition) {
		this.resourceFromProcessDefinition = resourceFromProcessDefinition;
	} 
	public String getPiId() {
		return piId;
	} 
	public void setPiId(String piId) {
		this.piId = piId;
	}

	public void setJbpmService(JbpmService jbpmService) {
		this.jbpmService = jbpmService;
	}

	public String index() throws Exception {
		XmlToProcessImage image = new XmlToProcessImage();
		resourceFromProcessInstance = jbpmService
				.getResourceFromProcessInstance(piId);
		resourceFromProcessDefinition = jbpmService
				.getResourceFromProcessDefinition(getId());
		image.setResourceFromProcessDefinition(resourceFromProcessDefinition);
		image.setResourceFromProcessInstance(resourceFromProcessInstance);
		image.outImage(getResponse());

		return super.index();
	}

}
